package prductsejb;

import java.util.ArrayList;

import javax.ejb.LocalBean;
import javax.ejb.Singleton;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

import products.Categoria;

/**
 * Session Bean implementation class CategoriaBean
 */

@Singleton
@LocalBean
public class CategoriaEJB {

	@PersistenceContext(unitName = "Sig_WorkFlow_And_Persistence")
	private EntityManager em;
	
	
	public Categoria createCategoria(Categoria cat) {
		em.persist(cat);
		return cat;
		}
	
	public ArrayList<Categoria> findCategoriasHabilitadas() {
		TypedQuery<Categoria> query = em.createNamedQuery("findAllCatHab", Categoria.class);
		return (ArrayList<Categoria>)query.getResultList();
	}
	
	public Categoria findCategoriaById(Integer id) {
		return em.find(Categoria.class, id);
		}
	
	public Categoria updateCategoria(Categoria cat) {
		return em.merge(cat);
	}
	
    public CategoriaEJB() {
        // TODO Auto-generated constructor stub
    }

}
